package com.bonc.ioc.service.impl;

import com.bonc.ioc.dao.FirstPageDao;
import com.bonc.ioc.dao.HotwordDao;
import com.bonc.ioc.dao.StatisticsDao;
import com.bonc.ioc.model.DataAssetInfo;
import com.bonc.ioc.service.FirstPageService;
import com.bonc.ioc.util.SizeConversionUtils;
import com.bonc.ioc.vo.HotWordVo;
import com.bonc.ioc.vo.ScientificDataVo;
import com.bonc.ioc.vo.TimeNumber;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * @author wxf
 * @Title
 * @Package
 * @Description 首页 热门词汇，特色资源，资源统计
 * @date 2021/4/914:21
 */
@Service
public class FirstPageServiceImpl implements FirstPageService {

    @Resource
    private FirstPageDao firstPageDao;

    @Resource
    private StatisticsDao statisticsDao;

    @Resource
    private HotwordDao hotwordDao;

    @Override
    public List<String> selectSearchHotWord() {
        List<String> hotWords = hotwordDao.selectHotword();
        return hotWords;
    }

    @Override
    public HashMap<String, Object> scientificData() {
        HashMap<String, Object> map = new HashMap<>(16);
        List<ScientificDataVo> data = firstPageDao.scientificData();
        for (ScientificDataVo datum : data) {
            String totalDataNum = SizeConversionUtils.getNumber(String.valueOf(datum.getDataNumbers())) + "条";
            datum.setDataNumbers(totalDataNum);
            String visitNum = SizeConversionUtils.getNumber(String.valueOf(datum.getVisitNumbers())) + "次";
            datum.setVisitNumbers(visitNum);
            String totalDataSize = SizeConversionUtils.getSize(String.valueOf(datum.getSizeNumbers()));
            datum.setSizeNumbers(totalDataSize);
            String totalUserdNum = SizeConversionUtils.getNumber(String.valueOf(datum.getUsedNumbers())) + "次";
            datum.setUsedNumbers(totalUserdNum);
        }
        List<DataAssetInfo> visitRanking = statisticsDao.queryDataAssetRanking(4);
        List<DataAssetInfo> logo = new LinkedList<>();
        List<DataAssetInfo> titleVos = new LinkedList<>();
        if ( !visitRanking.isEmpty() ) {
            if ( visitRanking.size() <= 4 ) {
                logo = visitRanking;
            }else {
                logo = visitRanking.subList(0,4);
                titleVos = visitRanking.subList(4,visitRanking.size());
            }
        }
        map.put("scientificData", data);
        map.put("scientificLogo", logo);
        map.put("scientificTitle", titleVos);
        return map;
    }

    @Override
    public HashMap<String, Object> getScientificData() {
        HashMap<String, Object> map = new HashMap<>();
        List<HotWordVo> hotWordVos = firstPageDao.selectUseHotWord();
        List<TimeNumber> timeNumbers = firstPageDao.selectVisitDataNumbers();
        List<HotWordVo> typeDataNumbers = firstPageDao.selectTypeDataNumbers();
        map.put("hotWordVos", hotWordVos);
        map.put("timeNumbers", timeNumbers);
        map.put("typeDataNumbers", typeDataNumbers);
        return map;
    }

}
